﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Dao;

namespace Pixysoft.Weblications.Sango.Command.party
{
    partial class SangoPartyHandler
    {
        public party_quit party_quit()
        {
            string userCode = SangoManager.Authentication();

            party_quit response = ReflectionManager.CreatePojo<party_quit>();
            response.Succeed = false;


            Entities.Usr_Profile profile = UsrProfileDao.getUsrProfile(userCode);
            Entities.Usr_Partymember member = PartyDao.tryGetActiveMember(userCode);

            if (member == null)
            {
                response.Message = "尚未加入军团";
                return response;
            }

            Entities.Usr_Party party = PartyDao.tryGetActiveParty(member.Partyprimarycode);

            if (party.Initializeusercode.Equals(userCode) || party.Precidentusercode.Equals(userCode))
            {
                response.Message = "军团长、创始人无法退出。";
                return response;
            }

            PartyDao.quitParty(party, member);

            IEntityNoebeTransaction transaction = SettingHelper.EntityTransaction;
            transaction.Begin(delegate()
            {
                transaction.Update(party);

                transaction.Update(member);

                transaction.Commit();
            });
            
            response.Succeed = true;
            return response;
        }


    }
    public interface party_quit : ISangoResponse
    {

    }
}
